package com.example.admin.yuejian21.fragment;

//
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.RadioButton;

import com.example.admin.yuejian21.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class JlbFragment extends Fragment {
    private RadioButton renqiButton;
    private RadioButton nearButton;
    private RenqiFragment renqiFragment;
    private NearFragment nearFragment;

    private FragmentManager fragmentManager;
    private FragmentTransaction transaction;

    public JlbFragment() {

        // Required empty public constructor
    }
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState){
        renqiButton= (RadioButton) view.findViewById(R.id.radioButton_renqi);
        nearButton= (RadioButton) view.findViewById(R.id.radioButton_near);
        renqiButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    renqiFragment=new RenqiFragment();
                    replacefragment(renqiFragment);

                }
            }
        });
        nearButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    nearFragment =new NearFragment();
                    replacefragment(nearFragment);

                }
            }
        });
        fragmentManager=getChildFragmentManager();
        renqiButton.setChecked(true);

    }
    private  void replacefragment(Fragment fragment){
        transaction=fragmentManager.beginTransaction();
        transaction.replace(R.id.fragment_holder,fragment);
        transaction.commit();
    }



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_jlb, container, false);
    }

}
